package com.example.demo.demo.utlls;

import java.util.concurrent.ThreadLocalRandom;

/**
 * TODO
 *
 * @author My
 * @date 2020/12/20 11:01
 */
public class RandomUtil {

    private final static String BASE_NUMBER = "1234567890";
    private final static String BASE_CAHR = "abcdefghijklmnopqrstuvwxyz";
    private final static String BASE_CHAR_NUMBER = BASE_CAHR + BASE_NUMBER;

    public static String newString(Integer length){
        return randomString(BASE_CHAR_NUMBER,length);
    }


    public static String randomString(String baseString,int length){
        final StringBuffer sb = new StringBuffer();
        if (length < 1){
            length = 1;
        }
        int baseLength = baseString.length();
        for(int i =0 ;i<length;i++){
            int number = getRandom().nextInt(baseLength);
            sb.append(baseString.charAt(number));
        }
        return sb.toString();


    }

    public static ThreadLocalRandom getRandom(){
        return ThreadLocalRandom.current();
    }
}
